// components/workitem/workitem.js
const app = getApp()
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    content:{
      type:Object
    }
  },
  methods: {
    isChange(e){
      const item = app.globalData.list.filter(item => item.index ===  this.properties.content.index)[0]
      item.isComplete = !item.isComplete
      this.properties.content.isComplete=!this.properties.content.isComplete
      this.triggerEvent("ischange")
      if(this.properties.content.isComplete){
        wx.showToast({
          title:'任务已完成',
          icon:'success'
        })
      }else{
        wx.showToast({
          title: '任务未完成',
          icon:'error'
        })
      }
      
    },
    remove(){
      wx.showModal({
        title: '确定删除',
        content: "任务内容："+this.properties.content.text,
        complete: (res) => {
          if (res.confirm) {
            const item = app.globalData.list.filter(item=> item.index === this.properties.content.index)[0]
            let index =  app.globalData.list.indexOf(item)
            app.globalData.list.splice(index,1)
            this.triggerEvent("ischange")
          }
        }
      })
    }
  }
})
